package gui.panels.media;

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.dnd.DragSource;

import javax.media.Player;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import javax.swing.JButton;

public class PlayerGUIPanel extends JPanel implements MediaContainer, Cloneable{
	
	private VideoControlsPanel videoControlsPanel = null;
	private Long startTime;
	private Long stopTime;
	private JPanel pnlContainer = null;
	private JButton btnDeattach = null;
	
	/**
	 * This is the default constructor
	 */
	public PlayerGUIPanel() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(337, 246);
		this.setLayout(null);
		
		
		this.add(getVideoControlsPanel(), getVideoControlsPanel().getName());
		this.add(getPnlContainer(), null);
		this.add(getBtnDeattach(), null);
		
	}

	/**
	 * This method initializes videoControlsPanel	
	 * 	
	 * @return gui.panels.media.VideoControlsPanel	
	 */
	private VideoControlsPanel getVideoControlsPanel() {
		if (videoControlsPanel == null) {
			videoControlsPanel = new VideoControlsPanel(getPnlContainer());
			videoControlsPanel.setBounds(new Rectangle(52, 220, 233, 18));
		}
		return videoControlsPanel;
	}
	
	public Player getPlayer(){
		return videoControlsPanel.getPlayer();
	}
	
	public void setStartTime(long time) {
		
		((MediaContainer)this.getVideoControlsPanel()).setStartTime(time);

	}

	
	public void setStopTime(long time) {
		
		((MediaContainer)this.getVideoControlsPanel()).setStopTime(time);

	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPnlContainer() {
		if (pnlContainer == null) {
			pnlContainer = new JPanel();
			
			pnlContainer.setLayout(null);
			pnlContainer.setBackground(Color.BLACK);
			pnlContainer.setBounds(new Rectangle(0, 1, 336, 216));
		}
		return pnlContainer;
	}

	/**
	 * This method initializes btnDeattach	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnDeattach() {
		if (btnDeattach == null) {
			btnDeattach = new JButton();
			btnDeattach.setBounds(new Rectangle(296, 221, 34, 15));
			btnDeattach.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					DeattachedMedia dm= null;
					try {
						dm = new DeattachedMedia((PlayerGUIPanel) getPlayerGUIPanel().clone());
					} catch (CloneNotSupportedException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					dm.setVisible(true);
				}
			});
		}
		return btnDeattach;
	}
	
	public PlayerGUIPanel getPlayerGUIPanel(){
		return this;
	}
 


}  //  @jve:decl-index=0:visual-constraint="10,10"  
